<?php

namespace App\Controller\System;

use App\Constants\ErrorCode;
use App\Controller\AbstractController;
use App\DataStore\RedisGeneral;
use App\Service\System\CaptchaService;
use Hyperf\Di\Annotation\Inject;

class SystemController extends AbstractController
{
    #[Inject]
    public CaptchaService $captchaService;

    public function getCaptcha(){
        return success($this->captchaService->getCaptcha());
    }

    public function current(){
        $userToken = $this->request->header('UTK');
        $userInfo = RedisGeneral::getInc()->getUserKey($userToken);
        if(empty($userInfo)){
            return error(null,ErrorCode::CODE_TYPE_ERROR_LOGIN_EXPIRE->getMessage(),ErrorCode::CODE_TYPE_ERROR_LOGIN_EXPIRE->value);
        }

        return success([
            'user_info' => jsonDecode($userInfo)
        ]);
    }
}